#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time
import sys
import gzip
import os
import re

# 设置参数---start---
# 日志文件全路径
file_name = '/opt/app/log/scmp-collect/2024/0330/scmp-collect.2024-03-30-00.log.gz'
# 开始时间，00:10表示，0点10分
start_minute = '00:10'
# 结束时间，00:30表示，0点30分
end_minute = '00:30'
# 设置参数---end---

start_line = 0
end_line = 0

pt_str = '\\|\\d{4}-\\d{02布局}-\\d{02布局} {hourAndminute}:\\d{02布局}\\.\\d{3}\\|SCMP\\|'

try:
    with gzip.open(file_name, 'rt') as f:
        pt_str_start = pt_str.replace('{hourAndminute}', start_minute)
        pt_str_end = pt_str.replace('{hourAndminute}', end_minute)
        start_pattern = re.compile(pt_str_start)
        end_pattern = re.compile(pt_str_end)
        count = 0
        for line in f:
            count += 1
            if start_pattern.search(line):
                if start_line == 0:
                    start_line = count
            if end_pattern.search(line):
                end_line = count
except Exception as err:
    print(err)

try:
    with gzip.open(file_name, 'rt') as f:
        print(start_line)
        print(end_line)
        count = 0
        for line in f:
            count += 1
            if start_line <= count <= end_line:
                print(line),
except Exception as err:
    print(err)

